package bTree.LeetCode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

public class 非递减子序列 {
    List<List<Integer>>res=new ArrayList<>();
    List<Integer>path=new ArrayList<>();
    public List<List<Integer>> findSubsequences(int[] nums) {
        backtracking(nums,0);
        return res;

    }

    private void backtracking(int[] nums, int startindex) {
        if(path.size()>1){
            res.add(new ArrayList<>(path));
            //不要return，还要继续下一层
        }
        //每一层用sey来记录使用过的
        HashSet<Integer>hashSet=new HashSet<>();
        for(int i=startindex;i<nums.length;i++){
            if(hashSet.contains(nums[i])||(!path.isEmpty())&&path.get(path.size()-1)>nums[i]){
                continue;
            }
                path.add(nums[i]);
                hashSet.add(nums[i]);
                backtracking(nums,i+1);
                path.remove(path.size()-1);

        }
    }
}

